package cn.wizzer.app.user.modules.models;

import cn.wizzer.framework.base.model.BaseModel;
import lombok.Data;
import org.nutz.dao.entity.annotation.*;
import org.nutz.dao.interceptor.annotation.PrevInsert;
import org.nutz.dao.interceptor.annotation.PrevUpdate;

import java.io.Serializable;
import java.math.BigDecimal;


/**
 * 红包记录
 */
@Data
@Table("red_packet_record")
public class RedPacketRecord extends BaseModel implements Serializable {

    @Column
    @Name
    @Comment("ID")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    @PrevInsert(els = {@EL("uuid()")})
    private String id;

    @Column
    @Comment("编号")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String no;

    @Column
    @Comment("红包ID")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String redPacketId;

    @Column
    @Comment("红包金额")
    @ColDefine(type = ColType.FLOAT, width = 16, precision = 6)
    private BigDecimal amount;

    @Comment("红包编号,从1开始生成")
    @Column
    @ColDefine(type = ColType.INT, width = 16)
    private Integer packetNo;

    /**
     * 可以不存这个字段，但还是让他冗余一下
     */
    @Comment("币种ID")
    @Column
    @ColDefine(type = ColType.VARCHAR, width = 32, notNull = true)
    private String currencyId;

    @Column
    @Comment("创建时间")
    @PrevInsert(els = @EL("$me.now()"))
    private Long ctAt;

    /**
     * 红包打开人，一开始为空
     */
    @Column
    @Comment("用户ID")
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String userId;


    @Column
    @Comment("打开时间")
    @PrevInsert(els = @EL("$me.now()"))
    @PrevUpdate(els = @EL("$me.now()"))
    //Long不要用ColDefine定义,兼容oracle/mysql,支持2038年以后的时间戳
    private Long openAt;

}
